$(function () {
    var getFilmUrl = '/film/queryfilmbyname';
    var hallUrl = '/hall/gethalllist';
    var getOrderUrl = '/order/getorderlist'
    $.getJSON(getFilmUrl, function(data){
        if (data.success){
            var film1 = data.film1;
            $('#picture1').attr('src',film1.filmPicture);
            $('#name1').html(film1.filmName);
            $('#desc1').html(film1.desc);
            //
            var film2 = data.film2;
            // $('#picture2').attr('src',film2.filmPicture);
            $('#name2').html(film2.filmName);
            $('#desc2').html(film2.desc);

            var film3 = data.film3;
            // $('#picture3').attr('src',film3.filmPicture);
            $('#name3').html(film3.filmName);
            $('#desc3').html(film3.desc)
        }
    });

    $('#submit1').click(function () {
        var formData = new FormData();
        formData.append("filmName", $('#name1').html());
        $.ajax({
            url: hallUrl,
            type: 'post',
            data: formData,
            contentType: false,
            processData: false,
            cache: false,
            success: function (data) {
                if (data.success) {
                    handleList(data.hallList);
                }
            }
        });
    });

        $('#submit2').click(function () {
            var formData = new FormData();
            formData.append("filmName", $('#name2').html());
            $.ajax({
                url: hallUrl,
                type: 'post',
                data: formData,
                contentType: false,
                processData: false,
                cache: false,
                success: function (data) {
                    if (data.success) {
                        handleList(data.hallList);
                    }
                }
            });
        });

            $('#submit3').click(function () {
                var formData = new FormData();
                formData.append("filmName", $('#name3').html());
                $.ajax({
                    url: hallUrl,
                    type: 'post',
                    data: formData,
                    contentType: false,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            handleList(data.hallList);
                        }
                    }
                });
            });
        function handleList(data) {
            html = '';
            data.map(function(item, index) {
                html += '<div class="row row-cinema temp"><div class="col-33">'
                    + item.hallId + '</div><div class="col-33">'
                    + item.hallFilmTime
                    + '</div><div class="col-33">'
                    + '<a href="#" class="button buy"'
                    + '>购票</a></div>'
                    + '</div>';
            });
            document.cookie = "html="+html;
            var url = "../html/hall.html";
            window.location.href = url;
        }
        $('#order').click(function () {
            $.getJSON(getOrderUrl,function (data) {
                if (data.success){
                    html = '';
                    var orderingList = data.orderingList;
                    orderingList.map(function(item, index) {
                        html += '<div class="row row-order temp">' +
                            '<div class="col-20">' + item.film.filmName + '</div>' +
                            '<div class="col-20">' + item.hall.hallFilmTime + '</div>' +
                            '<div class="col-20">' + item.hall.hallSerialNumber + '</div>' +
                            '<div class="col-20">' + item.seat.seatSerialNumber + '</div>' +
                            '<div class="col-20">'
                            + '<a href="#" class="button delete"'
                            + '>取消订单</a></div>'
                            + '</div>';
                    });
                    document.cookie = "orderingListhtml="+html;
                    window.location.href = "../html/order.html";
                }
            })
        })
});